﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.IO;
using System.Xml;
using BLL;
using DAL;
using Models;
using System.Data;

public partial class cn_member_center_user_password : System.Web.UI.Page
{
    // Fields
    protected string answer = "";

    protected UserManager um = new UserManager();
    protected string xmlPath = "/cn/xml/safety_question.xml";

    // Methods
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.Session["user"] == null)
        {
            base.Response.Redirect("/cn/web_login.html?ru=" + HttpContext.Current.Request.Url.PathAndQuery.Replace("aspx", "html"));
        }
    }

    protected StringBuilder QuestionBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.xmlPath));
            XmlNodeList childNodes = document.SelectSingleNode("security_question").ChildNodes;
            DataTable userById = this.um.GetUserById((this.Session["user"] as User).Id);
            this.answer = userById.Rows[0]["answer"].ToString();
            foreach (XmlNode node in childNodes)
            {
                XmlElement element = (XmlElement)node;
                builder.AppendLine("<option value=\"" + element.GetAttribute("value") + "\" " + ((userById.Rows[0]["question"].ToString() == element.GetAttribute("value")) ? "selected='selected'" : "") + ">" + element.GetAttribute("value") + "</option>");
            }
        }
        catch
        {
        }
        return builder;
    }

}